package tr.net.ems.esmart;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class KampanyaActivity extends Activity 
{
	public int currentimageindex=0;
	Timer timer;
	TimerTask task;
	
	private int[] IMAGE_IDS = {
			R.drawable.kamp1, R.drawable.kamp2,R.drawable.kamp3
		};
	private ImageView slidingimage;
	
	
    

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kampanya);
		
		RelativeLayout kamp = (RelativeLayout)findViewById(R.id.kamp);
		
		slidingimage = new ImageView(this);
		
		int w = getWindowManager().getDefaultDisplay().getWidth();
	    int h = getWindowManager().getDefaultDisplay().getHeight();
	    
	    /************************* LOGO ***************************************/
	    final RelativeLayout.LayoutParams logolay = new RelativeLayout.LayoutParams(
	            new RelativeLayout.MarginLayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
	           		 							RelativeLayout.LayoutParams.WRAP_CONTENT));
		
	    logolay.height= (int) (h/2);
	    logolay.width = (int)(w);
	    logolay.setMargins(0,(int)((h - h/2) / 2), 0, 0);
	    kamp.addView(slidingimage, logolay);
		
		final Handler mHandler = new Handler();
		final Animation rotateimage2 = AnimationUtils.loadAnimation(this, R.anim.custom_anim2);
        // Create runnable for posting
        final Runnable mUpdateResults = new Runnable() {
            public void run() {
            	slidingimage.startAnimation(rotateimage2);
            	AnimateandSlideShow();
            	
            }
        };
		
        int delay = 1000; // delay for 1 sec.

        int period = 4000; // repeat every 4 sec.

        Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {

        	 mHandler.post(mUpdateResults);

        }

        }, delay, period);
		
		
	}
	
private void AnimateandSlideShow() {
    	
    	
    	
   		slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
   		
   		currentimageindex++;
    	
   		Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
   		
    	  
        
    	  slidingimage.startAnimation(rotateimage);
    	  //slidingimage.startAnimation(rotateimage2);
          
          	 
        
    }
    
}
